clc 
close all
clear all
sample_size = 2000;
coefficient = 8/6;
%%PRKS
prks95_delayslot = GetStableRegionDelay('prks95_delayslot_type2.txt',sample_size);
prks95_delayslot = sort(prks95_delayslot);
prks90_delayslot = GetStableRegionDelay('prks90_delayslot_type2.txt',sample_size);
prks90_delayslot = sort(prks90_delayslot);
prks80_delayslot = GetStableRegionDelay('prks80_delayslot_type2.txt',sample_size);
prks80_delayslot = sort(prks80_delayslot);
prks70_delayslot = GetStableRegionDelay('prks70_delayslot_type2.txt',sample_size);
prks70_delayslot = sort(prks70_delayslot);
prks60_delayslot = GetStableRegionDelay('prks60_delayslot_type2.txt',sample_size);
prks60_delayslot = sort(prks60_delayslot);
prks50_delayslot = GetStableRegionDelay('prks50_delayslot_type2.txt',sample_size);
prks50_delayslot = sort(prks50_delayslot);
prks40_delayslot = GetStableRegionDelay('prks40_delayslot_type2.txt',sample_size);
prks40_delayslot = sort(prks40_delayslot);
prks30_delayslot = GetStableRegionDelay('prks40_delayslot_type2.txt',sample_size);
prks30_delayslot = sort(prks30_delayslot);
%%RID
rid95_delayslot = GetStableRegionDelay('rid95_delayslot_type2.txt',sample_size);
rid95_delayslot = sort(rid95_delayslot);
rid90_delayslot = GetStableRegionDelay('rid90_delayslot_type2.txt',sample_size);
rid90_delayslot = sort(rid90_delayslot);
rid80_delayslot = GetStableRegionDelay('rid80_delayslot_type2.txt',sample_size);
rid80_delayslot = sort(rid80_delayslot);
rid70_delayslot = GetStableRegionDelay('rid70_delayslot_type2.txt',sample_size);
rid70_delayslot = sort(rid70_delayslot);
%%B-MAC
csma_delayslot = GetStableRegionDelay('csma_delayslot_type2.txt',sample_size);
csma_delayslot = sort(csma_delayslot*8/6);
%%S-MAC
rtscts_delayslot = GetStableRegionDelay('rtscts_delayslot_type2.txt',sample_size);
rtscts_delayslot = sort(rtscts_delayslot*8/6);
%%CMAC
cmac95_delayslot = GetStableRegionDelay('cmac95_delayslot_type2.txt',sample_size);
cmac95_delayslot = sort(cmac95_delayslot*8/6);
cmac90_delayslot = GetStableRegionDelay('cmac90_delayslot_type2.txt',sample_size);
cmac90_delayslot = sort(cmac90_delayslot*8/6);
cmac80_delayslot = GetStableRegionDelay('cmac80_delayslot_type2.txt',sample_size);
cmac80_delayslot = sort(cmac80_delayslot*8/6);
cmac70_delayslot = GetStableRegionDelay('cmac70_delayslot_type2.txt',sample_size);
cmac70_delayslot = sort(cmac70_delayslot*8/6);
%%SCREAM
scream_delayslot = GetStableRegionDelay('scream_delayslot_type2.txt',sample_size);
scream_delayslot = sort(scream_delayslot);
%%---------------------CDF PLOT--------------------------------------------
h1 = cdfplot(prks95_delayslot);
hold on;
set(h1, 'color', 'r', 'Marker', '*');
h2 = cdfplot(prks90_delayslot);
hold on;
set(h2, 'color', 'r', 'Marker', '+');
h3 = cdfplot(prks80_delayslot);
hold on;
set(h3, 'color', 'r', 'Marker', 'o');
h4 = cdfplot(prks70_delayslot);
hold on;
set(h4, 'color', 'r', 'Marker', 'x');
h_prks60 = cdfplot(prks60_delayslot);
hold on;
set(h_prks60, 'color', 'r', 'Marker', '.');
h_prks50 = cdfplot(prks50_delayslot);
hold on;
set(h_prks50, 'color', 'r', 'Marker', 's');
h_prks40 = cdfplot(prks40_delayslot);
hold on;
set(h_prks40, 'color', 'r', 'Marker', 'd');
h_prks30 = cdfplot(prks30_delayslot);
hold on;
set(h_prks30, 'color', 'r', 'Marker', '^');


h5 = cdfplot(rid95_delayslot);
hold on;
set(h5, 'color', 'c', 'Marker','*');
h6 = cdfplot(rid90_delayslot);
hold on;
set(h6, 'color', 'c', 'Marker', '+');
h7 = cdfplot(rid80_delayslot);
hold on;
set(h7, 'color', 'c', 'Marker', 'o');
h8 = cdfplot(rid70_delayslot);
hold on;
set(h8, 'color', 'c', 'Marker', 'x');

h9 = cdfplot(cmac95_delayslot);
hold on;
set(h9, 'color', 'b', 'Marker', '*');
h10 = cdfplot(cmac90_delayslot);
hold on;
set(h10, 'color', 'b', 'Marker', '+');
h11 = cdfplot(cmac80_delayslot);
hold on;
set(h11, 'color', 'b', 'Marker', 'o');
h12 = cdfplot(cmac70_delayslot);
hold on;
set(h12, 'color', 'b', 'Marker', 'x');

h13 = cdfplot(csma_delayslot);
hold on;
set(h13, 'color', 'm');

h14 = cdfplot(rtscts_delayslot);
hold on;
set(h14, 'color', 'k');

h15 = cdfplot(scream_delayslot);
hold on;
set(h15, 'color', 'g');
legend ('PRKS95','PRKS90','PRKS80','PRKS70','PRKS60','PRKS50','PRKS40','PRKS30','RIDB95','RIDB90','RIDB80','RIDB70','CMAC95','CMAC90','CMAC80','CMAC70','CSMA','RTS-CTS','SCREAM');
set(gca,'XScale','log');
%%---------------------BAR GRAPH-------------------------------------------
%% MEDIAN
%{
ALPHA=0.05;
Median = zeros(4,6);
Error_Median_Lower = zeros (4,6);
Error_Median_Upper = zeros (4,6);
Median(1,1) = median(prks70_delayslot);
Median(1,2) = median(csma_delayslot);
Median(1,3) = median(rtscts_delayslot);
Median(1,4) = median(rid70_delayslot);
Median(1,5) = median(cmac70_delayslot);
Median(1,6) = median(scream_delayslot);
prks70_length=size(prks70_delayslot);
index_lower = prks70_length(1,2)/2 - 1.96*sqrt(prks70_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(1,1) = prks70_delayslot(index_lower);
index_upper = 1 + prks70_length(1,2)/2  + 1.96*sqrt(prks70_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(1,1) = prks70_delayslot (index_upper);

csma_length=size(csma_delayslot);
index_lower = csma_length(1,2)/2 - 1.96*sqrt(csma_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(1,2) = csma_delayslot(index_lower);
index_upper = 1 + csma_length(1,2)/2  + 1.96*sqrt(csma_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(1,2) = csma_delayslot (index_upper);

rtscts_length=size(rtscts_delayslot);
index_lower = rtscts_length(1,2)/2 - 1.96*sqrt(rtscts_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(1,3) = rtscts_delayslot(index_lower);
index_upper = 1 + rtscts_length(1,2)/2  + 1.96*sqrt(rtscts_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(1,3) = rtscts_delayslot (index_upper);

rid70_length=size(rid70_delayslot);
index_lower = rid70_length(1,2)/2 - 1.96*sqrt(rid70_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(1,4) = rid70_delayslot(index_lower);
index_upper = 1 + rid70_length(1,2)/2  + 1.96*sqrt(rid70_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(1,4) = rid70_delayslot (index_upper);

cmac70_length=size(cmac70_delayslot);
index_lower = cmac70_length(1,2)/2 - 1.96*sqrt(cmac70_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(1,5) = cmac70_delayslot(index_lower);
index_upper = 1 + cmac70_length(1,2)/2  + 1.96*sqrt(cmac70_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(1,5) = cmac70_delayslot (index_upper);

scream_length=size(scream_delayslot);
index_lower = scream_length(1,2)/2 - 1.96*sqrt(scream_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(1,6) = scream_delayslot(index_lower);
index_upper = 1 + scream_length(1,2)/2  + 1.96*sqrt(scream_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(1,6) = scream_delayslot (index_upper);

Median(2,1) = median(prks80_delayslot);
Median(2,2) = median(csma_delayslot);
Median(2,3) = median(rtscts_delayslot);
Median(2,4) = median(rid80_delayslot);
Median(2,5) = median(cmac80_delayslot);
Median(2,6) = median(scream_delayslot);

prks80_length=size(prks80_delayslot);
index_lower = prks80_length(1,2)/2 - 1.96*sqrt(prks80_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(2,1) = prks80_delayslot(index_lower);
index_upper = 1 + prks80_length(1,2)/2  + 1.96*sqrt(prks80_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(2,1) = prks80_delayslot (index_upper);

csma_length=size(csma_delayslot);
index_lower = csma_length(1,2)/2 - 1.96*sqrt(csma_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(2,2) = csma_delayslot(index_lower);
index_upper = 1 + csma_length(1,2)/2  + 1.96*sqrt(csma_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(2,2) = csma_delayslot (index_upper);

rtscts_length=size(rtscts_delayslot);
index_lower = rtscts_length(1,2)/2 - 1.96*sqrt(rtscts_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(2,3) = rtscts_delayslot(index_lower);
index_upper = 1 + rtscts_length(1,2)/2  + 1.96*sqrt(rtscts_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(2,3) = rtscts_delayslot (index_upper);

rid80_length=size(rid80_delayslot);
index_lower = rid80_length(1,2)/2 - 1.96*sqrt(rid80_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(2,4) = rid80_delayslot(index_lower);
index_upper = 1 + rid80_length(1,2)/2  + 1.96*sqrt(rid80_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(2,4) = rid80_delayslot (index_upper);

cmac80_length=size(cmac80_delayslot);
index_lower = cmac80_length(1,2)/2 - 1.96*sqrt(cmac80_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(2,5) = cmac80_delayslot(index_lower);
index_upper = 1 + cmac80_length(1,2)/2  + 1.96*sqrt(cmac80_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(2,5) = cmac80_delayslot (index_upper);

scream_length=size(scream_delayslot);
index_lower = scream_length(1,2)/2 - 1.96*sqrt(scream_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(2,6) = scream_delayslot(index_lower);
index_upper = 1 + scream_length(1,2)/2  + 1.96*sqrt(scream_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(2,6) = scream_delayslot (index_upper);

Median(3,1) = median(prks90_delayslot);
Median(3,2) = median(csma_delayslot);
Median(3,3) = median(rtscts_delayslot);
Median(3,4) = median(rid90_delayslot);
Median(3,5) = median(cmac90_delayslot);
Median(3,6) = median(scream_delayslot);

prks90_length=size(prks90_delayslot);
index_lower = prks90_length(1,2)/2 - 1.96*sqrt(prks90_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(3,1) = prks90_delayslot(index_lower);
index_upper = 1 + prks90_length(1,2)/2  + 1.96*sqrt(prks90_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(3,1) = prks90_delayslot (index_upper);

csma_length=size(csma_delayslot);
index_lower = csma_length(1,2)/2 - 1.96*sqrt(csma_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(3,2) = csma_delayslot(index_lower);
index_upper = 1 + csma_length(1,2)/2  + 1.96*sqrt(csma_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(3,2) = csma_delayslot (index_upper);

rtscts_length=size(rtscts_delayslot);
index_lower = rtscts_length(1,2)/2 - 1.96*sqrt(rtscts_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(3,3) = rtscts_delayslot(index_lower);
index_upper = 1 + rtscts_length(1,2)/2  + 1.96*sqrt(rtscts_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(3,3) = rtscts_delayslot (index_upper);

rid90_length=size(rid90_delayslot);
index_lower = rid90_length(1,2)/2 - 1.96*sqrt(rid90_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(3,4) = rid90_delayslot(index_lower);
index_upper = 1 + rid90_length(1,2)/2  + 1.96*sqrt(rid90_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(3,4) = rid90_delayslot (index_upper);

cmac90_length=size(cmac90_delayslot);
index_lower = cmac90_length(1,2)/2 - 1.96*sqrt(cmac90_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(3,5) = cmac90_delayslot(index_lower);
index_upper = 1 + cmac90_length(1,2)/2  + 1.96*sqrt(cmac90_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(3,5) = cmac90_delayslot (index_upper);

scream_length=size(scream_delayslot);
index_lower = scream_length(1,2)/2 - 1.96*sqrt(scream_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(3,6) = scream_delayslot(index_lower);
index_upper = 1 + scream_length(1,2)/2  + 1.96*sqrt(scream_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(3,6) = scream_delayslot (index_upper);

Median(4,1) = median(prks95_delayslot);
Median(4,2) = median(csma_delayslot);
Median(4,3) = median(rtscts_delayslot);
Median(4,4) = median(rid95_delayslot);
Median(4,5) = median(cmac95_delayslot);
Median(4,6) = median(scream_delayslot);

prks95_length=size(prks95_delayslot);
index_lower = prks95_length(1,2)/2 - 1.96*sqrt(prks95_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(4,1) = prks95_delayslot(index_lower);
index_upper = 1 + prks95_length(1,2)/2  + 1.96*sqrt(prks95_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(4,1) = prks95_delayslot (index_upper);

csma_length=size(csma_delayslot);
index_lower = csma_length(1,2)/2 - 1.96*sqrt(csma_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(4,2) = csma_delayslot(index_lower);
index_upper = 1 + csma_length(1,2)/2  + 1.96*sqrt(csma_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(4,2) = csma_delayslot (index_upper);

rtscts_length=size(rtscts_delayslot);
index_lower = rtscts_length(1,2)/2 - 1.96*sqrt(rtscts_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(4,3) = rtscts_delayslot(index_lower);
index_upper = 1 + rtscts_length(1,2)/2  + 1.96*sqrt(rtscts_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(4,3) = rtscts_delayslot (index_upper);

rid95_length=size(rid95_delayslot);
index_lower = rid95_length(1,2)/2 - 1.96*sqrt(rid95_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(4,4) = rid95_delayslot(index_lower);
index_upper = 1 + rid95_length(1,2)/2  + 1.96*sqrt(rid95_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(4,4) = rid95_delayslot (index_upper);

cmac95_length=size(cmac95_delayslot);
index_lower = cmac95_length(1,2)/2 - 1.96*sqrt(cmac95_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(4,5) = cmac95_delayslot(index_lower);
index_upper = 1 + cmac95_length(1,2)/2  + 1.96*sqrt(cmac95_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(4,5) = cmac95_delayslot (index_upper);

scream_length=size(scream_delayslot);
index_lower = scream_length(1,2)/2 - 1.96*sqrt(scream_length(1,2))/2;
index_lower = floor(index_lower);
Error_Median_Lower(4,6) = scream_delayslot(index_lower);
index_upper = 1 + scream_length(1,2)/2  + 1.96*sqrt(scream_length(1,2))/2;
index_upper = floor(index_upper);
Error_Median_Upper(4,6) = scream_delayslot (index_upper);

%barerrorbar({1:size(log(Median), 1), log(Median)}, {repmat((1:size(log(Median), 1))', 1, size(lags, 1)), log(Median), log(Error_Median_Lower), log(Error_Median_Upper), 'x'});
barerrorbar({log(Median)},{log(Error_Median_Lower), log(Error_Median_Upper),'x'});
legend('PRKS','CSMA','RTS-CTS','RIDB','CMAC','SCREAM','orientation','horizontal');
xlabel('PDR requirements (%)');
ylabel('Log(median delay)');
ylim([0,25]);
%}
%{

ALPHA=0.05;
MEAN = zeros(4,6);
Error_MEAN = zeros (4,6);
MEAN(1,1) = mean(prks70_delayslot);
MEAN(1,2) = mean(csma_delayslot);
MEAN(1,3) = mean(rtscts_delayslot);
MEAN(1,4) = mean(rid70_delayslot);
Error_MEAN(1,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks70_delayslot) / sqrt(size(prks70_delayslot, 1));
Error_MEAN(1,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma_delayslot) / sqrt(size(csma_delayslot, 1));
Error_MEAN(1,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts_delayslot) / sqrt(size(rtscts_delayslot, 1));
Error_MEAN(1,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid70_delayslot) / sqrt(size(rid70_delayslot, 1));
MEAN(1,5) = mean(cmac70_delayslot);
Error_MEAN(1,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac70_delayslot) / sqrt(size(cmac70_delayslot, 1));
MEAN(1,6) = mean(scream_delayslot);
Error_MEAN(1,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream_delayslot) / sqrt(size(scream_delayslot, 1));
%==
MEAN(2,1) = mean(prks80_delayslot);
MEAN(2,2) = mean(csma_delayslot);
MEAN(2,3) = mean(rtscts_delayslot);
MEAN(2,4) = mean(rid80_delayslot);
Error_MEAN(2,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks80_delayslot) / sqrt(size(prks80_delayslot, 1));
Error_MEAN(2,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma_delayslot) / sqrt(size(csma_delayslot, 1));
Error_MEAN(2,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts_delayslot) / sqrt(size(rtscts_delayslot, 1));
Error_MEAN(2,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid80_delayslot) / sqrt(size(rid80_delayslot, 1));
MEAN(2,5) = mean(cmac80_delayslot);
Error_MEAN(2,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac80_delayslot) / sqrt(size(cmac80_delayslot, 1));
MEAN(2,6) = mean(scream_delayslot);
Error_MEAN(2,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream_delayslot) / sqrt(size(scream_delayslot, 1));
%==
MEAN(3,1) = mean(prks90_delayslot);
MEAN(3,2) = mean(csma_delayslot);
MEAN(3,3) = mean(rtscts_delayslot);
MEAN(3,4) = mean(rid90_delayslot);
Error_MEAN(3,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks90_delayslot) / sqrt(size(prks90_delayslot, 1));
Error_MEAN(3,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma_delayslot) / sqrt(size(csma_delayslot, 1));
Error_MEAN(3,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts_delayslot) / sqrt(size(rtscts_delayslot, 1));
Error_MEAN(3,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid90_delayslot) / sqrt(size(rid90_delayslot, 1));
MEAN(3,5) = mean(cmac90_delayslot);
Error_MEAN(3,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac90_delayslot) / sqrt(size(cmac90_delayslot, 1));
MEAN(3,6) = mean(scream_delayslot);
Error_MEAN(3,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream_delayslot) / sqrt(size(scream_delayslot, 1));
%==
MEAN(4,1) = mean(prks95_delayslot);
MEAN(4,2) = mean(csma_delayslot);
MEAN(4,3) = mean(rtscts_delayslot);
MEAN(4,4) = mean(rid95_delayslot);
Error_MEAN(4,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks95_delayslot) / sqrt(size(prks95_delayslot, 1));
Error_MEAN(4,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma_delayslot) / sqrt(size(csma_delayslot, 1));
Error_MEAN(4,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts_delayslot) / sqrt(size(rtscts_delayslot, 1));
Error_MEAN(4,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid95_delayslot) / sqrt(size(rid95_delayslot, 1));
MEAN(4,5) = mean(cmac95_delayslot);
Error_MEAN(4,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac95_delayslot) / sqrt(size(cmac95_delayslot, 1));
MEAN(4,6) = mean(scream_delayslot);
Error_MEAN(4,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream_delayslot) / sqrt(size(scream_delayslot, 1));
%==



figure;
handle = barweb(log(MEAN), log(Error_MEAN),1, ['70%';'80%';'90%';'95%'], [], ['PDR requirement'], ['Log(mean delay)'], jet);
handle.legend =legend ('PRKS','CSMA','RTS-CTS','RIDB','CMAC','SCREAM','orientation','horizontal');
set(gca,'fontsize',36);
%set(gca,'fontsize',60);
box on
maximize ();


clc 
close all
clear all
sample_size = 2000;
prks95_cov = GetLinkCov('prks95_delayslot_type2.txt',sample_size);
prks90_cov = GetLinkCov('prks90_delayslot_type2.txt',sample_size);
prks80_cov = GetLinkCov('prks80_delayslot_type2.txt',sample_size);
prks70_cov = GetLinkCov('prks70_delayslot_type2.txt',sample_size);

%%RID

rid95_cov = GetLinkCov('rid95_delayslot_type2.txt',sample_size);
rid90_cov = GetLinkCov('rid90_delayslot_type2.txt',sample_size);
rid80_cov = GetLinkCov('rid80_delayslot_type2.txt',sample_size);
rid70_cov = GetLinkCov('rid70_delayslot_type2.txt',sample_size);


%%B-MAC
csma_cov = GetLinkCov('csma_delayslot_type2.txt',sample_size);

%%S-MAC
rtscts_cov = GetLinkCov('rtscts_delayslot_type2.txt',sample_size);


%%CMAC

cmac95_cov = GetLinkCov('cmac95_delayslot_type2.txt',sample_size);
cmac90_cov = GetLinkCov('cmac90_delayslot_type2.txt',sample_size);
cmac80_cov = GetLinkCov('cmac80_delayslot_type2.txt',sample_size);
cmac70_cov = GetLinkCov('cmac70_delayslot_type2.txt',sample_size);

%%SCREAM
scream_cov = GetLinkCov('scream_delayslot_type2.txt',sample_size);


ALPHA=0.05;
MEAN = zeros(4,6);
Error_MEAN = zeros (4,6);
MEAN(1,1) = mean(prks70_cov);
MEAN(1,2) = mean(csma_cov);
MEAN(1,3) = mean(rtscts_cov);
MEAN(1,4) = mean(rid70_cov);
Error_MEAN(1,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks70_cov) / sqrt(size(prks70_cov, 1));
Error_MEAN(1,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma_cov) / sqrt(size(csma_cov, 1));
Error_MEAN(1,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts_cov) / sqrt(size(rtscts_cov, 1));
Error_MEAN(1,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid70_cov) / sqrt(size(rid70_cov, 1));
MEAN(1,5) = mean(cmac70_cov);
Error_MEAN(1,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac70_cov) / sqrt(size(cmac70_cov, 1));
MEAN(1,6) = mean(scream_cov);
Error_MEAN(1,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream_cov) / sqrt(size(scream_cov, 1));
%==
MEAN(2,1) = mean(prks80_cov);
MEAN(2,2) = mean(csma_cov);
MEAN(2,3) = mean(rtscts_cov);
MEAN(2,4) = mean(rid80_cov);
Error_MEAN(2,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks80_cov) / sqrt(size(prks80_cov, 1));
Error_MEAN(2,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma_cov) / sqrt(size(csma_cov, 1));
Error_MEAN(2,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts_cov) / sqrt(size(rtscts_cov, 1));
Error_MEAN(2,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid80_cov) / sqrt(size(rid80_cov, 1));
MEAN(2,5) = mean(cmac80_cov);
Error_MEAN(2,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac80_cov) / sqrt(size(cmac80_cov, 1));
MEAN(2,6) = mean(scream_cov);
Error_MEAN(2,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream_cov) / sqrt(size(scream_cov, 1));
%==
MEAN(3,1) = mean(prks90_cov);
MEAN(3,2) = mean(csma_cov);
MEAN(3,3) = mean(rtscts_cov);
MEAN(3,4) = mean(rid90_cov);
Error_MEAN(3,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks90_cov) / sqrt(size(prks90_cov, 1));
Error_MEAN(3,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma_cov) / sqrt(size(csma_cov, 1));
Error_MEAN(3,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts_cov) / sqrt(size(rtscts_cov, 1));
Error_MEAN(3,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid90_cov) / sqrt(size(rid90_cov, 1));
MEAN(3,5) = mean(cmac90_cov);
Error_MEAN(3,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac90_cov) / sqrt(size(cmac90_cov, 1));
MEAN(3,6) = mean(scream_cov);
Error_MEAN(3,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream_cov) / sqrt(size(scream_cov, 1));
%==
MEAN(4,1) = mean(prks95_cov);
MEAN(4,2) = mean(csma_cov);
MEAN(4,3) = mean(rtscts_cov);
MEAN(4,4) = mean(rid95_cov);
Error_MEAN(4,1) =  norminv(1 - ALPHA / 2, 0, 1) * std(prks95_cov) / sqrt(size(prks95_cov, 1));
Error_MEAN(4,2) =  norminv(1 - ALPHA / 2, 0, 1) * std(csma_cov) / sqrt(size(csma_cov, 1));
Error_MEAN(4,3) =  norminv(1 - ALPHA / 2, 0, 1) * std(rtscts_cov) / sqrt(size(rtscts_cov, 1));
Error_MEAN(4,4) =  norminv(1 - ALPHA / 2, 0, 1) * std(rid95_cov) / sqrt(size(rid95_cov, 1));
MEAN(4,5) = mean(cmac95_cov);
Error_MEAN(4,5) =  norminv(1 - ALPHA / 2, 0, 1) * std(cmac95_cov) / sqrt(size(cmac95_cov, 1));
MEAN(4,6) = mean(scream_cov);
Error_MEAN(4,6) =  norminv(1 - ALPHA / 2, 0, 1) * std(scream_cov) / sqrt(size(scream_cov, 1));
%==



figure;
handle = barweb(log(MEAN), log(Error_MEAN),1, ['70%';'80%';'90%';'95%'], [], ['PDR requirement'], ['Coefficient of variation'], jet);
handle.legend =legend ('PRKS','CSMA','RTS-CTS','RIDB','CMAC','SCREAM','orientation','horizontal');
set(gca,'fontsize',36);
%set(gca,'fontsize',60);
box on
maximize ();
%}
